#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n;
    cin>>n;
    vector<int>v(n+1);
    auto w=v;
    int s1=0,s2=0;
    int a=0,b=0;
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];
        if(v[i]==w[i])
        {
            if(v[i]==1)s1++;
            else if(v[i]==-1)s2++;
        }
        else
        {
            if(v[i]>w[i])a+=v[i];
            else b+=w[i];
        }
    }
    int mn=min(a,b),mx=max(a,b),x=s1-s2;
    while(s1&&mn<mx)
    {
        s1--;
        mn++;
    }
    while(s2&&mn<mx)
    {
        s2--;
        mx--;
    }
    if(mn==mx)
    {
        x=s1-s2;
        if(x>=0)cout<<mn+x/2<<endl;
        else cout<<mn+(x-1)/2<<endl;
    }
    else 
    {
        cout<<mn<<endl;
    }
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}